
class UnionFind():
    def __init__(self, node_num):
        self.node_num = node_num
        self.parent = [i for i in range(node_num+1)]
        
    def find(self, node):
        if self.parent[node] != node:
            self.parent[node] = self.find(self.parent[node])
            
        return self.parent[node]

    def union(self, s, t):

        parent_s = self.find(s)
        parent_t = self.find(t)
        if parent_t != parent_s:
            self.parent[parent_t] = parent_s
            
    def is_same(self, node1, node2):
        return self.find(node1) == self.find(node2)
    

def main():
    node_num, edge_num = map(int, input().split())
    uf = UnionFind(node_num)
    
    for i in range(edge_num):
        s, t = map(int, input().split())
        uf.union(s, t)
    
    source, dest = map(int, input().split())
    
    if uf.is_same(source, dest): 
        print(1)
    else:
        print(0)

main()
        